home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / ContextWarrior.sit / ContextWarrior / source code / MoreFiles 1.4.6 / !MoreFiles Read Me next >
Text File  |  1997-02-23  |  24KB  |  297 lines

  1. MoreFiles
  2.  
  3. A collection of File Manager and related routines
  4.  
  5. by Jim Luther (Apple Macintosh Developer Technical Support Emeritus)
  6. with significant code contributions by Nitin Ganatra (Apple Macintosh Developer Technical Support Emeritus)
  7. Copyright © 1992-1997 Apple Computer, Inc.
  8. Portions copyright © 1995 Jim Luther
  9. All rights reserved.
  10.  
  11. You may incorporate this sample code into your applications without restriction, though the sample code has been provided "AS IS" and the responsibility for its operation is 100% yours.  However, what you are not permitted to do is to redistribute the source as "DSC Sample Code" after having made changes. If you're going to re-distribute the source, we require that you make it clear in the source that the code was descended from Apple Sample Code, but that you've made changes.
  12.  
  13.  
  14. What is MoreFiles?
  15.  
  16. MoreFiles is a collection of high-level routines written over the last couple of years to answer File Manager questions developers have sent to Apple Developer Technical Support and to answer questions on various online services and the internet. The routines have been tested (but not stress-tested), documented, code-reviewed, and used in both my own programs and in many commercial products.
  17.  
  18.  
  19. Important Note
  20.  
  21. These routines are meant to be used from an application environment. In particular, some routines use static variables which require an A5 world and almost all routines make calls that are unsafe at interrupt time (i.e., synchronous File Manager calls and Memory Manager calls). If you plan to use these routines from stand-alone code modules, you may need to make some modifications to the code that uses static variables. Don't even think about using most of these routines from code that executes at interrupt time.
  22.  
  23. Note: If you need to use the routines in FSpCompat in stand-alone 68K code, set GENERATENODATA to 1 in FSpCompat.c (or pass it in) so globals (static variables) are not used.
  24.  
  25.  
  26. Build Environments
  27.  
  28. MoreFiles is built using the latest release C development environments I have access to. In particular, MoreFiles v1.4.6 was built using:
  29.  
  30. •  Universal Interfaces 2.1.x in “MPW Latest” on MPW Pro #21
  31. •  Latest MPW from E.T.O./MPW Pro #21 (with Universal Interfaces 2.1.x in “MPW Latest” on MPW Pro #21)
  32. •  THINK C 7.0.5/Symantec C++ 8.0.3 (with Universal Interfaces 2.1.x in “MPW Latest” on MPW Pro #21)
  33. •  Metrowerks CodeWarrior 10.0 (MW C/C++ 68K 1.6 and MW C/C++ PPC 1.6 with Universal Interfaces 2.1.x in “MPW Latest” on MPW Pro #21)
  34.  
  35. Note: If you are not using these versions, you might have to make some minor changes to compile or link with MoreFiles. I've tried hard to write C code that compiles with no warnings using all current development environments.
  36.  
  37. The Pascal interfaces to MoreFiles are maintained, but have not been tested with all available Pascal development environments.
  38.  
  39.  
  40. Files in the MoreFile Package
  41.  
  42. MoreFiles.c - the “glue code” for high-level and FSSpec style routines that were never implemented or added to the standard interface for one reason or another. If you're uncomfortable filling in parameter blocks, you'll find the code in this file very useful.
  43.  
  44. MoreFiles.h and MoreFiles.p - the documentation and header files for calling the routines included in MoreFiles.c.
  45.  
  46. Sharing.h and Sharing.p - the inline “glue code” for calling the AppleShare server routines, PBShare, PBUnshare, and PBGetUGEntry. These routines have been added to Files.h in the Universal Interfaces so they aren't used by MoreFiles. However, I've left them here in case you're still using the old interfaces.
  47.  
  48. MoreFilesExtras.c - a collection of useful File Manager utility routines.
  49.  
  50. MoreFilesExtras.h and MoreFilesExtras.p - the documentation and header files for calling the routines included in MoreFilesExtras.c. I recommend that you browse through the header files - you'll probably find a routine that you've always wanted.
  51.  
  52. MoreDesktopMgr.c - a collection of useful high-level Desktop Manager routines. If the Desktop Manager isn't available, the "Desktop" file is used for 'read' operations.
  53.  
  54. MoreDesktopMgr.h and MoreDesktopMgr.p - the documentation and header files for calling the routines included in MoreDesktopMgr.c.
  55.  
  56. FileCopy.c - a robust, general purpose file copy routine that does everything the right way. Copying a file on the Macintosh isn't as simple as you'd think if you want to handle all cases (i.e., file server drop boxes, preflighting disk space, etc.). This routine does it all and is fast, too.
  57.  
  58. FileCopy.h and FileCopy.p - the documentation and header files for calling the routines included in FileCopy.c.
  59.  
  60. DirectoryCopy.c - a general purpose recursive directory copy routine with a hook for your error handling routine and a hook for filtering what you want or don't want copied.
  61.  
  62. DirectoryCopy.h and DirectoryCopy.p - the documentation and header files for calling the routines included in DirectoryCopy.c.
  63.  
  64. FSpCompat.c - the “glue code” for FSSpec style routines that will work under System 6 as much as possible. If you still need to support System 6, you'll find the code in this file very useful.
  65.  
  66. FSpCompat.h and FSpCompat.p -  the documentation and header files for calling the routines included in FSpCompat.c.  
  67.  
  68. Search.c - IndexedSearch and PBCatSearchSyncCompat. IndexedSearch performs an indexed search in and below the specified directory using the same parameters as is passed to PBCatSearch. PBCatSearchSyncCompat uses PBCatSearch (if available) or IndexedSearch (if PBCatSearch is not available) to search a volume. Also included are a couple of examples of how to call PBCatSearch: one that searches by creator and file type, and one that searches by file name.
  69.  
  70. Search.h and Search.p - the documentation and header files for calling the routines included in Search.c.  
  71.  
  72. FullPath.c - Routines for dealing with full pathnames… if you really must use them. Read the warning at the top of the interface files for reasons why you shouldn't use them most of the time.
  73.  
  74. FullPath.h and FullPath.p - the documentation and header files for calling the routines included in FullPath.c.  
  75.  
  76. IterateDirectory.c - Routines that perform a recursive iteration (scan) of a specified directory and call your IterateFilterProc function once    for each file and directory found. IterateDirectory lets you decide how deep you want the function to dive into the directory tree - anything from 1 level or all levels. This routine is very useful when you want to do something to each item in a directory.
  77.  
  78. IterateDirectory.h and IterateDirectory.p - the documentation and header files for calling the routines included in IterateDirectory.c.
  79.  
  80. MoreFiles.68K.π - the THINK C project file you can use to build a 68K THINK library.
  81.  
  82. MoreFiles.PPC.π - the Symantec C++ project file you can use to build a PowerPC Symantec library.
  83.  
  84. MoreFiles.68K.µ - the Metrowerks C project file you can use to build a 68K CodeWarrior library.
  85.  
  86. MoreFiles.PPC.µ - the Metrowerks C project file you can use to build a PowerPC CodeWarrior library.
  87.  
  88. BuildMoreFiles Metrowerks - the AppleScript  used to compile and build the Metrowerks CodeWarrior versions of the libraries.
  89.  
  90. BuildMoreFiles and MoreFilesLib.make - the MPW script and make file used to compile and build the MPW versions of the libraries.
  91.  
  92. FindFolderGlue.o - a library containing the FindFolder compatibility glue. This library is needed only by THINK Pascal users. Read “FindFolderGlue Read Me” for details.
  93.  
  94. UpperString.p - a UNIT that maps UpperString to UprString for THINK Pascal users.
  95.  
  96. Note: All 68K libraries are built with SystemSevenOrLater false so that all compatibility code is included.
  97.  
  98.  
  99. How to use MoreFiles
  100.  
  101. You can compile the code, put it in a library, and link it into your programs. You can cut and paste it into your programs. You can use it as example code. Feel free to rip it off and modify it in whatever ways you find work best for you.
  102.  
  103. All exported routines use Pascal calling conventions so this code can be used from either C or Pascal. (Note: Pascal calling conventions can be turned off starting with MoreFiles 1.4.2. BE CAREFUL WITH THE CALLBACKS if you use this option!)
  104.  
  105. You'll also notice that all routines that make other File Manager calls return an OSErr result. I always check for error results and you should too. (Well, there's a few places where I purposely ignore errors, but they're commented in the source.)
  106.  
  107.  
  108. Documentation
  109.  
  110. The documentation for the routines can be found in the C header files. There, you'll find a short description of each call and a complete listing of all input and output parameters. I've also included a list of possible result codes for each routine. For example, here's the documentation for one of the routines, GetFileLocation.
  111.  
  112.     /*****************************************************************************/
  113.     
  114.     pascal  OSErr   GetFileLocation(short refNum,
  115.                                     short *vRefNum,
  116.                                     long *dirID,
  117.                                     StringPtr fileName);
  118.     /*  ¶ Get the location of an open file.
  119.         The GetFileLocation function gets the location (volume reference number,
  120.         directory ID, and fileName) of an open file.
  121.         
  122.         refNum      input:  The file reference number of an open file.
  123.         vRefNum     output: The volume reference number.
  124.         dirID       output: The parent directory ID.
  125.         fileName    input:  Points to a buffer (minimum Str63) where the
  126.                             filename is to be returned or must be nil.
  127.                     output:    The filename.
  128.      
  129.         Result Codes
  130.             noErr        0  No error
  131.             nsvErr     -35  Specified volume doesn’t exist
  132.             fnOpnErr   -38  File not open
  133.             rfNumErr   -51  Reference number specifies nonexistent
  134.                             access path
  135.         __________
  136.         
  137.         See also:   FSpGetFileLocation
  138.     */
  139.     
  140.     /*****************************************************************************/
  141.  
  142. Some routines have very few comments in their code because they simply make a single File Manager call. For those routines, the routine description is the comment. However, you'll find that more complicated routines have plenty of comments to clarify what and why the code is doing something. If something isn't clear, take a look at "Inside Macintosh: Files" and the TechNote "Inside Macintosh: Files - Errata" for further reference.
  143.  
  144.  
  145. Release Notes
  146.  
  147. v1.0     09/14/93
  148. v1.1     01/22/94
  149. v1.1.1  02/01/94
  150. v1.2     07/20/94
  151. v1.2.1  08/09/94
  152. v1.2.2  11/01/94
  153. v1.3     04/17/95
  154. v1.3.1  06/17/95
  155. ________________________________________
  156.  
  157. v1.4  12/21/95
  158.  
  159. New Routines:
  160. •  Added directory scanning functions, IterateDirectory and FSpIterateDirectory in a new files IterateDirectory.c, IterateDirectory.h and IterateDirectory.p. Check these routines out. I think you'll find them useful.
  161. •  Added SetDefault and RestoreDefault to MoreFileExtras. These routines let you set the default directory for those times when you're stuck calling standard C I/O or a library that takes only a filename.
  162. •  Added XGetVInfo to MoreFilesExtras. Like GetVInfo, this routine returns the volume name, volume reference number, and free bytes on the volume; like HGetVInfo, XGetVInfo also returns the total number of bytes on the volume. Both freeBytes and totalBytes are UnsignedWide values so this routine can report volume size information for volumes up to 2 terabytes. XGetVInfo's glue code calls through to HGetVInfo if needed to provide backwards compatibility.
  163.  
  164. Bugs fixed:
  165. •  Fixed bug where FileCopy could pass NULL to CopyFileMgrAttributes if PBHCopyFile was used.
  166. •  Added 68K alignment to MoreDesktopMgr.c structs.
  167. •  Added 68K alignment to MoreFilesExtras.p records.
  168.  
  169. Other changes:
  170. •  Conditionalized FSpCompat.c with SystemSevenOrLater and SystemSevenFiveOrLater so the FSSpec compatibility code is only included when needed. It makes the code a little harder to read, but it removes 2K-3K of code and the overhead of additional calls when SystemSevenOrLater and SystemSevenFiveOrLater are true. See ConditionalMacros.h for an explanation of SystemSevenOrLater and SystemSevenFiveOrLater.
  171. •  Moved the code to create a full pathname from GetFullPath to FSpGetFullPath. This accomplished two goals: (1) when FSpGetFullPath is used, the input FSSpec isn't passed to FSMakeFSSpecCompat (it was already an FSSpec) and (2) the code is now smaller. While I was in the code, I changed a couple of calls from Munger to PtrToHand.
  172. •  Changed GetDirID to GetDirectoryID so that MoreFiles could be used by MacApp programs (There's a MacApp method named GetDirID).
  173. •  Changed DirIDFromFSSpec to FSpGetDirectoryID to be consistent in naming conventions.
  174. •  Added macros wrapped with "#if OLDROUTINENAMES … #endif" so GetDirID and DirIDFromFSSpec will still work with your old code.
  175. •  Changed alignment #if's to use PRAGMA_ALIGN_SUPPORTED instead of GENERATINGPOWERPC (will they ever stop changing?).
  176. •  Changed all occurances of filler2 to ioACUser to match the change in Universal Interfaces 2.1.
  177. •  Added type-casts from "void *" to "Ptr" in various places to get rid of compiler warnings.
  178. •  Added CallCopyErrProc to DirectoryCopy.h and DirectoryCopy.c (it just looks better that way).
  179. •  Added the "__cplusplus" conditional code around all .h header files so they'll work with C++.
  180. •  Built libraries with Metrowerks, THINK C, and MPW so everyone can link.
  181.  
  182. ________________________________________
  183.  
  184. v1.4.1  1/6/96
  185.  
  186. Bugs fixed:
  187. •  Fixed the conditionalized code FSpCreateCompat.
  188. •  Fixed the conditionalized code FSpExchangeFilesCompat.
  189. •  Fixed the conditionalized code FSpCreateResFileCompat.
  190.  
  191. Other changes:
  192. •  Changed PBStatus(&pb, false) to PBStatusSync(&pb) in GetDiskBlocks.
  193. ________________________________________
  194.  
  195. v1.4.2  3/25/96
  196.  
  197. New Routines:
  198. •  Added FSpResolveFileIDRef to MoreFiles.
  199. •  Added GetIOACUser and FSpGetIOACUser to MoreFilesExtras. These routines let you get a directory's access privileges for the current user.
  200. •  Added bit masks, macros, and function for testing ioACUser values to MoreFilesExtras.h and MoreFilesExtras.p.
  201. •  Added GetVolumeInfoNoName to MoreFilesExtras to put common calls to PBHGetVInfo in one place. Functions that call GetVolumeInfoNoName are: (in DirectoryCopy.c) PreflightDirectoryCopySpace, (in FileCopy.c) PreflightFileCopySpace, (in MoreFilesExtras.c) DetermineVRefNum, CheckVolLock, FindDrive, UnmountAndEject, (in Search.c) CheckVol.
  202. •  Added GetCatInfoNoName to MoreFilesExtras to put common calls to PBGetCatInfo in one place. Functions that call GetCatInfoNoName are: (in FileCopy.c) GetDestinationDirInfo, (in MoreDesktopMgr.c) GetCommentID, (in MoreFilesExtras.c) GetDInfo, GetDirectoryID, CheckObjectLock.
  203. •  Added TruncPString to MoreFilesExtras. This lets you shorten a Pascal string without breaking the string in the middle of a multi-byte character.
  204. •  Added FilteredDirectoryCopy and FSpFilteredDirectoryCopy to DirectoryCopy. FilteredDirectoryCopy and FSpFilteredDirectoryCopy work just like DirectoryCopy and FSpDirectoryCopy only they both take an optional CopyFilterProc parameter which can point to routine you supply. The CopyFilterProc lets your code decide what files or directories are copied to the destination. DirectoryCopy and FSpDirectoryCopy now call through to FilteredDirectoryCopy with a NULL CopyFilterProc.
  205.  
  206. Bugs fixed:
  207. •  Fixed minor bug in GetDiskBlocks where driveQElementPtr->dQRefNum was checked when driveQElementPtr could be NULL.
  208. •  DirectoryCopy didn't handle error conditions correctly. In some cases, DirectoryCopy would return noErr when there was a problem and in other cases, the CopyErrProc wasn't called and the function immediately failed.
  209. •  The result of DirectoryCopy's CopyErrProc was documented incorrectly.
  210.  
  211. Other changes and improvements:
  212. •  Added result codes to function descriptions in the C header files (these probably aren't a perfect list of possible errors, but they should catch most of the results you'll ever see).
  213. •  Removed most of the function descriptions in Pascal interface files since they haven't been completely in sync with the C headers for some time and I don't have time to keep the documentation in both places up to date.
  214. •  Rewrote HMoveRenameCompat so it doesn't use the Temporary Items folder.
  215. •  Added parameter checking to OnLine so that it doesn't allow the volIndex parameter to be less than or equal to 0.
  216. •  Added parameter checking to GetDirItems so that it doesn't allow the itemIndex parameter to be less than or equal to 0.
  217. •  FSpExchangeFilesCompat now returns diffVolErr (instead of paramErr)    if the source and the destination are on different volumes.
  218. •  Changed GetDirName's name parameter to Str31 and added parameter checking so that it doesn't allow a NULL name parameter.
  219. •  Forced errors returned by MoreDesktopMgr routines to be closer to what would be expected if the low-level Desktop Manager calls were used.
  220. •  Added conditionalized changes from Fabrizio Oddone so that Pascal calling conventions can be easily disabled. Disabling Pascal calling conventions reduces the code size slightly and allows C compilers to optimize parameter passing. NOTE: If you disable Pascal calling conventions, you'll have to remove the "pascal" keyword from all of the MoreFiles callbacks you've defined in your code.
  221. •  Changed DirectoryCopy so that you can copy the source directory's content to a disk's root directory.
  222. •  Added a build script and a make file for MPW libraries.
  223. •  Added a build script for Metrowerks CodeWarrior libraries.
  224. •  Added a build script for Symantec THINK Project Manager and Symantec Project Manager libraries.
  225. •  Renamed the Symantec and Metrowerks project files.
  226. •  Changed MoreFile's directory structure so that C headers, Pascal interfaces, and the source code aren't in the main directory.
  227.  
  228. Thanks to Fabrizio Oddone for supplying the conditionalized changes that optionally remove Pascal calling conventions. Thanks to Byron Han for beating the bugs out of DirectoryCopy and for suggesting and prototyping the changes needed for the "copy to root directory" option and the FilteredDirectoryCopy routine in DirectoryCopy.
  229. ________________________________________
  230.  
  231. v1.4.3  8/24/96
  232.  
  233. Bugs fixed:
  234. •  Fixed bug in GetDriverName where dctlDriver is a handle. It was not dereferenced correctly.
  235. •  Fixed the MPW build file, BuildMoreFiles, so it would correctly pass options to MoreFilesLib.make.
  236. •  GetFullPath now returns fullPathLength = 0 and fullPath = NULL as documented.
  237.  
  238. Other changes and improvements:
  239. •  Added PBXGetVolInfoSync glue code to MoreFilesExtras.c when GENERATINGCFM is true. This allows building with no link errors where PBXGetVolInfoSync isn't inluded in your development system's standard libraries. This routine shouldn't be needed in MoreFiles at some point in the future after it has been added to your development system's standard libraries.
  240. •  Changed BuildMoreFiles and MoreFilesLib.make to use the MrC compiler instead of the PPCC compiler.
  241. •  Removed “BuildMoreFiles Symantec” because it's much simpler to include MoreFiles as a subproject in your Symantec project instead of building a library and then including it.
  242. •  Removed non-strict ANSI comment from PascalElim.h and used conditional code instead.
  243. •  GetFullPath and FSpGetFullPath return full pathname to directories with a trailing colon character.  For example, they now return "MyVolume:MyDirectory:" instead of "MyVolume:MyDirectory".
  244. •  Changed the MoreFiles feedback email address (below) in this Read Me file.
  245. ________________________________________
  246.  
  247. v1.4.4  12/18/96
  248.  
  249. Bugs fixed:
  250. •  Added  "| REGISTER_RESULT_LOCATION(kRegisterD0)" to uppFSDispatchProcInfo in PBXGetVolInfoSync. (the code produced is the same since REGISTER_RESULT_LOCATION(kRegisterD0) happens to be 0).
  251. •  Initialized ioDTReqCount before calling PBDTGetComment. See the comment in DTGetComment in MoreDesktopMgr.c for the reasons why.
  252. •  Fixed paramErr check in GetDirName in MoreFilesExtras.c so it actually works.
  253. •  Rewrote CopyDirectoryAccess in MoreFilesExtras.c for better error handling.
  254. •  Fixed error handling in GetAPPLFromDesktopFile in MoreDesktopMgr.c.
  255. •  Fixed off by one errors in GetLocalIDFromFREF and GetIconRsrcIDFromLocalID in MoreDesktopMgr.c.
  256. •  Changed IterateDirectoryLevel so that it continues iterating when it finds a directory that cannot be accessed due to an afpAccessDenied error.
  257.  
  258. Other changes and improvements:
  259. •  Added const type qualifier to input-only pointer parameters. That includes changing many StringPtr parameters to ConstStr255Param (thanks to Stephen C. Gilardi for starting this project).
  260. •  General cleanup to improve readability and code generation.
  261. •  Added DTXGetAPPL to MoreDesktopMgr. DTXGetAPPL works like DTGetAPPL only it has an additional input parameter, searchCatalog. If searchCatalog is set to false, the catalog search is skipped if the    application isn't found in the desktop database or desktop file. This is useful if you need to find the application quickly (the catalog search can be quite time consuming).
  262. •  Removed "BuildMoreFiles Metrowerks" script. I've decided that it's too hard to keep the scripts working with current IDEs.
  263. •  Removed pre-v1.4 release notes from this file because it was too big for SimpleText.
  264. ________________________________________
  265.  
  266. v1.4.5  12/20/96
  267.  
  268. Bugs fixed:
  269. •  Fixed logic bug in HOpenAware and HOpenRFAware. Those two functions and FileCopy (which calls them) DO NOT work in MoreFiles version 1.4.4.
  270. ________________________________________
  271.  
  272. v1.4.6  2/15/97
  273.  
  274. Bugs fixed:
  275. •  Fixed bug in PreflightFileCopySpace (FileCopy.c) introduced in MoreFiles version 1.4.4.
  276. •  Fixed problem between PBXGetVolInfoSync and __WANTPASCALELIMINATION conditional.
  277. •  HMoveRenameCompat from v1.4.2 through v1.4.5 worked with files but not folders, and comments were not being moved along with the file. Reverted HMoveRenameCompat to the v1.4.1 source and then fixed the possible collision in the Temporary Items folder by creating a new uniquely named subfolder in the Temporary Items folder.
  278.  
  279. Other changes and improvements:
  280. •  Added GetVolState function to MoreFilesExtras. Use GetVolState to determine a volume’s online and eject state and the volume driver’s need for eject requests.
  281. •  Added GetVolFileSystemID function to MoreFilesExtras.
  282. •  Renamed PascalElim.h to Optimization.h since it now contains additional optimization directives.
  283. •  Added OptimizationEnd.h.
  284. •  Checks for __WANTPASCALELIMINATION now use #if instead of #ifdef to be consistant with other conditionals in MoreFiles and in Apple interfaces.
  285. •  Added “#pragma internal on” if “__MWERKS__” is defined to Optimization.h and OptimizationEnd.h to produce better code under Metrowerks compilers.
  286. •  In Optimization.h, define __WANTPASCALELIMINATION to 0 if not already defined so __WANTPASCALELIMINATION can be passed in from the command line.
  287. •  In FSpCompat.c, define GENERATENODATA to 0 if not already defined so GENERATENODATA can be passed in from the command line.
  288. •  Added FSpDTXGetAPPL to MoreDesktopMgr.
  289. •  Added echo lines to MoreFilesLib.make so the build process can be monitored.
  290. ________________________________________
  291.  
  292. Thanks again (you know who you are) for the bug reports and suggestions that helped improve MoreFiles since the last version(s). If you find any more bugs or have any comments, please let us know at:
  293.  
  294. Internet: devsupport@apple.com
  295.  
  296. Please put "Attn: MoreFiles, DTS/ADS group" in the message title.
  297.